#include "junix.h"

int main(int argc, char **argv)
{
	FILE *fp;
	char name[1024];
	char buf[1024];
	char cmd[1024];

	int count=0;
	int ret;

	if(argc != 3)
		err_quit("Usage:%s tag init_num",argv[0]);

	count=atoi(argv[2]);

	fp=popen("ls -rt Flash*","r");
	if(!fp)
		err_sys("popen");

	while( fgets(buf,1024,fp) != NULL)
	{
		int pos = strlen(buf)-1;
		if(buf[pos]=='\n')
			buf[pos]='\0';

		sprintf(name," %s%03d",argv[1],count++);
		strncpy(cmd,"mv ",1024);
		strncat(cmd,buf,1024);
		strncat(cmd,name,1024);

		if( (ret=system(cmd)))
			err_quit("mv error");
	}

	if( (ret=pclose(fp)) )
		err_quit("ls error");

    exit(0);
}

